#ifndef LCD_H
#define LCD_H

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_mac.h"  // 手动包含 esp_mac.h 头文件
#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "font5x7.h"


// 引脚定义
#define LCD_HOST SPI2_HOST
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 19
#define PIN_NUM_CS 22
#define PIN_NUM_DC 21
#define PIN_NUM_RST 18
//分辨率
#define SCREEN_WIDTH 160
#define SCREEN_HEIGHT 128

// 结构体定义
typedef struct {
    uint8_t cmd;
    uint8_t data[16];
    uint8_t databytes;
} lcd_init_cmd_t;

// 函数声明
void lcd_init(spi_device_handle_t spi);
void lcd_cmd(spi_device_handle_t spi, const uint8_t cmd, bool keep_cs_active);
void lcd_data(spi_device_handle_t spi, const uint8_t *data, int len);
void lcd_spi_pre_transfer_callback(spi_transaction_t *t);
void write_one_dot(spi_device_handle_t spi, uint16_t color);
void Lcd_SetBox(spi_device_handle_t spi, int x0, int y0, int x1, int y1);
void draw_pixel(spi_device_handle_t spi, int x, int y, uint16_t color);
void draw_char(spi_device_handle_t spi, int x, int y, char c, uint16_t color, uint16_t bgcolor);
void draw_str(spi_device_handle_t spi, int x, int y, const char *str, uint16_t color, uint16_t bgcolor);
void clear_screen(spi_device_handle_t spi, uint16_t color);
void init_spi_bus(void);
spi_device_handle_t init_spi_device(void);
void init_lcd(spi_device_handle_t spi);
#endif // LCD_H
